<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class example extends CI_Controller {

    public function __construct() {
        parent::__construct();

        $this->load->library('auth');
        $this->load->library('base');
        $this->load->library('ajaxresponse');
        $this->load->library('datatables');
        $this->load->library("phpexcel");
        $this->load->library("PHPExcel/iofactory");
    }

    public function excel() {
        $objPHPExcel = new PHPExcel();
        $objPHPExcel->getProperties()->setTitle("title")
                ->setDescription("description");

        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setAutoSize(true);
        $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setAutoSize(true);
        $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setAutoSize(true);
        $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setAutoSize(true);


        $objPHPExcel->getActiveSheet()->getPageMargins()->setTop(1);
        $objPHPExcel->getActiveSheet()->getPageMargins()->setRight(0.75);
        $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft(0.75);
        $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom(1);

        $objPHPExcel->getActiveSheet()->getStyle('A1')->getBorders()->getBottom()->setBorderStyle(PHPExcel_Style_Border::BORDER_THICK);
        $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
        $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
        $objPHPExcel->getActiveSheet()->duplicateStyle( $objPHPExcel->getActiveSheet()->getStyle('A1'), 'B1:D1' );


//$objPHPExcel->getActiveSheet()->setBreak( 'A10' , PHPExcel_Worksheet::BREAK_ROW );
        // Assign cell values
        
        $objPHPExcel->getActiveSheet()->setCellValue('A1', "No");
        $objPHPExcel->getActiveSheet()->setCellValue('B1', "Decription");
        
        $i = 2;
        for (; $i < 200; $i++) {
            $objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $i);
            $objPHPExcel->getActiveSheet()->setCellValue('B' . $i, 'Test value');
        }
        $objPHPExcel->getActiveSheet()->setCellValue("A$i", "=SUM(A1:A".($i-1).")");
        $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&L&G&C&HLaporan Bla Bla Bla\n!');
        $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&B' . $objPHPExcel->getProperties()->getTitle() . '&RPage &P of &N');

        // Save it as an excel 2003 file
        header('Content-Type: application/vnd.ms-excel');
        header('Content-Disposition: attachment;filename="testets.xls"');
        header('Cache-Control: max-age=0');

        $objWriter = IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('php://output');
    }

    public function forms() {
        $this->auth->is_logged_in('form/login');
        $this->base->head_html('Market Forms');
        $this->load->view('forms');
    }

    public function dashboard() {
        $this->auth->is_logged_in('form/login');
        $this->base->head_html('Market Dashboards');
        $this->load->view('dashboard');
    }

    public function styles() {
        $this->auth->is_logged_in('form/login');
        $this->base->head_html('Market styles');
        $this->load->view('styles');
    }

    public function datatable() {
        $this->auth->is_logged_in('form/login');
        $this->base->head_html('Market Data Table');
        $this->load->view('datatable');
    }

    public function ajax() {
        $this->response = new ajaxresponse();
        $this->response->data['WEB_NAME'] = $this->input->post('WEB_NAME');
        $this->response->data['WEB_DESCRIPTION'] = $this->input->post('WEB_DESCRIPTION');
        $this->response->data['IS_MAINTENANCE'] = $this->input->post('IS_MAINTENANCE');
        $this->response->data['WEB_LOGO'] = $this->input->post('WEB_LOGO');

        $this->response->status = 'ok';
        $this->response->messages[] = 'what??';

        echo json_encode($this->response);
    }

    public function get_data2() {
        $this->load->model('m_member');

        $this->response = new ajaxresponse();
        $this->response->data = $this->m_member->get()->result();

        $this->response->status = 'ok';
        $this->response->messages[] = 'what??';

        echo json_encode($this->response);
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */